﻿using CloudApiServer.Model;
using Google.Protobuf.WellKnownTypes;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.X509;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using System.Web;
using System.Web.Caching;
using System.Web.Http;
using System.Web.Routing;
using static log4net.Appender.RollingFileAppender;

namespace CloudApiServer.Controllers
{
    /// <summary>
    /// 医保挡板管理接口控制器
    /// </summary>
    [RoutePrefix("FsiAdminApi")]
    public class FsiAdminApiController : ApiController
    {
        /// <summary>
        /// 新增医保人员信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("InsertPsnInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertPsnInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertPsnInfo";
            DataTable dt = new DataTable();
            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：入参的参数为空!", data = "" };
                        return Json(response);
                    }
                    List<Insuinfo> Insuinfolist = new List<Insuinfo>();
                    List<Idetinfo> Idetinfolist = new List<Idetinfo>();
                    FsiHeader<outputQueryPsnInfo> fsiRequest = JsonConvert.DeserializeObject<FsiHeader<outputQueryPsnInfo>>(request.Content.ReadAsStringAsync().Result);
                    string cert_no = fsiRequest.output.baseinfo.certno;
                    Insuinfolist = fsiRequest.output.insuinfo;
                    Idetinfolist = fsiRequest.output.idetinfo;
                    if (cert_no == "")
                    {
                        var response = new { code = 100, msg = $"参数校验失败：未传入人员身份信息cert_no!", data = "" };
                        return Json(response);

                    }
                    if (Insuinfolist.Count == 0)
                    {
                        var response = new { code = 100, msg = $"参数校验失败：入的参保信息Insuinfo列表为空！", data = "" };
                        return Json(response);
                    }
                    if (Insuinfolist.Count > 1)
                    {
                        var response = new { code = 100, msg = $"业务参数校验失败：传入的参保信息Insuinfo列表存在多条数据，挡板暂只支持插入一条数据，请挑选处理入参后重试！", data = "" };
                        return Json(response);
                    }
                    if (Idetinfolist.Count>1)
                    {
                        var response = new { code = 100, msg = $"业务参数校验失败：传入的身份信息Idetinfo列表存在多条数据，挡板暂只支持插入一条数据，请挑选处理入参后重试！", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    using (MySqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "select * from fsi_PsnInfo where certno=@certno";
                        cmd.Parameters.AddWithValue("@certno", cert_no);
                        using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                        {
                            dt.Load(reader);
                            cmd.Parameters.Clear();
                            // 检查 paus_insu_date 是否为 null 或空字符串
                            string paus_insu_date = string.IsNullOrEmpty(Insuinfolist[0].paus_insu_date) ? "2099-01-01" : Insuinfolist[0].paus_insu_date;

                            if (dt.Rows.Count == 0)
                            {
                                cmd.CommandText = "INSERT INTO `data`.`fsi_psninfo` (`certno`, `psn_no`, `gend`, `exp_content`, `brdy`, `naty`, `psn_cert_type`" +
                                    ", `psn_name`,`psn_mgtcode`, `insuplc_admdvs`, `psn_insu_date`, `cvlserv_flag`, `balc`, `emp_name`, `psn_type`, `psn_insu_stas`," +
                                    " `insutype`, `paus_insu_date`,`psn_idet_type`,`psn_type_lv`,`memo`,`begntime`,`endtime`) VALUES (@certno, @psn_no, @gend, @exp_content, @brdy, @naty,@psn_cert_type, @psn_name," +
                                    " @psn_mgtcode,@insuplc_admdvs, @psn_insu_date, @cvlserv_flag,@balc, @emp_name, @psn_type, @psn_insu_stas, @insutype, @paus_insu_date" +
                                    ", @psn_idet_type, @psn_type_lv, @memo, @begntime, @endtime)";
                                
                                cmd.Parameters.AddWithValue("@certno",fsiRequest.output.baseinfo.certno);
                                cmd.Parameters.AddWithValue("@psn_no", fsiRequest.output.baseinfo.psn_no);
                                cmd.Parameters.AddWithValue("@gend", fsiRequest.output.baseinfo.gend);
                                cmd.Parameters.AddWithValue("@exp_content", fsiRequest.output.baseinfo.exp_content);
                                cmd.Parameters.AddWithValue("@brdy", fsiRequest.output.baseinfo.brdy);
                                cmd.Parameters.AddWithValue("@naty", fsiRequest.output.baseinfo.naty);
                                cmd.Parameters.AddWithValue("@psn_cert_type", fsiRequest.output.baseinfo.psn_cert_type);
                                cmd.Parameters.AddWithValue("@psn_name", fsiRequest.output.baseinfo.psn_name);
                                cmd.Parameters.AddWithValue("@psn_mgtcode", fsiRequest.output.baseinfo.psn_mgtcode);
                                cmd.Parameters.AddWithValue("@insuplc_admdvs", Insuinfolist[0].insuplc_admdvs);
                                cmd.Parameters.AddWithValue("@psn_insu_date", Insuinfolist[0].psn_insu_date);
                                cmd.Parameters.AddWithValue("@cvlserv_flag", Insuinfolist[0].cvlserv_flag);
                                cmd.Parameters.AddWithValue("@balc", Insuinfolist[0].balc);
                                cmd.Parameters.AddWithValue("@emp_name", Insuinfolist[0].emp_name);
                                cmd.Parameters.AddWithValue("@psn_type", Insuinfolist[0].psn_type);
                                cmd.Parameters.AddWithValue("@psn_insu_stas", Insuinfolist[0].psn_insu_stas);
                                cmd.Parameters.AddWithValue("@insutype", Insuinfolist[0].insutype);
                                cmd.Parameters.AddWithValue("@paus_insu_date", paus_insu_date);
                                if (Idetinfolist.Count==0)
                                {
                                    cmd.Parameters.AddWithValue("@psn_idet_type", "");
                                    cmd.Parameters.AddWithValue("@psn_type_lv", "");
                                    cmd.Parameters.AddWithValue("@memo", "");
                                    cmd.Parameters.AddWithValue("@begntime", "");
                                    cmd.Parameters.AddWithValue("@endtime", "");
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue("@psn_idet_type", Idetinfolist[0].psn_idet_type);
                                    cmd.Parameters.AddWithValue("@psn_type_lv", Idetinfolist[0].psn_type_lv);
                                    cmd.Parameters.AddWithValue("@memo", Idetinfolist[0].memo);
                                    cmd.Parameters.AddWithValue("@begntime", Idetinfolist[0].begntime);
                                    cmd.Parameters.AddWithValue("@endtime", Idetinfolist[0].endtime);
                                }


                                await cmd.ExecuteNonQueryAsync();
                                cmd.Parameters.Clear();
                                var response = new { code = 0, msg = "", data = "插入成功!" };
                                return Json(response);
                            }
                            else
                            {
                                var response = new { code = 100, msg = $"业务参数校验失败：插入人员信息表失败！{cert_no}已有{dt.Rows.Count}条相关数据！无需再次插入！", data = "" };
                                return Json(response);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync(); 
                    }
                }
            }
        }

        /// <summary>
        /// 删除医保人员信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeletePsnInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> DeletePsnInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeletePsnInfo";

            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：入参为空!请检查!", data = "" };
                        return Json(response);
                    }
                    var fsiRequest = JsonConvert.DeserializeObject<DeletePsnInfoInput>(request.Content.ReadAsStringAsync().Result);
                    if (string.IsNullOrEmpty(fsiRequest.certno))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的人员身份证号为空!", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    DataTable dt = new DataTable();
                    using (MySqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "select * from fsi_PsnInfo where certno=@certno";
                        cmd.Parameters.AddWithValue("@certno", fsiRequest.certno);
                        using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                        {
                            dt.Load(reader);
                            cmd.Parameters.Clear();
                            if (dt.Rows.Count > 0)
                            {
                                cmd.CommandText = "delete from fsi_PsnInfo where certno=@certno";
                                cmd.Parameters.AddWithValue("@certno", fsiRequest.certno);
                                await cmd.ExecuteNonQueryAsync();
                                cmd.Parameters.Clear();
                                var response = new { code = 0, msg = "", data = "删除医保人员信息记录成功!" };
                                return Json(response);
                            }
                            else
                            {
                                var response = new { code = 100, msg = $"业务参数校验失败：删除医保人员信息记录失败！传入的人员身份证号{fsiRequest.certno}查询到{dt.Rows.Count}条相关数据！无需删除！", data = "" };
                                return Json(response);
                            }
                        }

                    }
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync();
                    }
                }
            }
        }



        /// <summary>
        /// 新增处方信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("InsertEpcInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertEpcInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertEpcInfo";
            DataTable dt = new DataTable();
            DataTable dtrxinfo = new DataTable();
            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        throw new Exception("入参为空!请检查!");
                    }

                    InsertEpcInfoInput epcInfoInput = JsonConvert.DeserializeObject<InsertEpcInfoInput>(request.Content.ReadAsStringAsync().Result);
                    List<RxDetlList> dataList = new List<RxDetlList>();
                    string psn_no = epcInfoInput.inputJson.Input.data.psn_no;
                    string auth_rxno= epcInfoInput.inputJson.Input.data.auth_rxno;
                    string epc_token = epcInfoInput.inputJson.Input.data.epc_token;
                    string certno="";
                    dataList = epcInfoInput.outputJson.output.rxDetlList;
                    await conn.OpenAsync();
                    using (MySqlTransaction transaction = conn.BeginTransaction())
                    {
                        using (MySqlCommand cmd = conn.CreateCommand())
                        {
                            cmd.CommandText = "select * from fsi_PsnInfo where psn_no=@psn_no";
                            cmd.Parameters.AddWithValue("@psn_no", psn_no);
                            using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                            {
                                dt.Load(reader);
                                cmd.Parameters.Clear();
                                if (dt.Rows.Count == 0)
                                {
                                    throw new Exception($"插入处方记录表失败！人员信息校验失败！不存在 {psn_no} 人员信息，请调用人员信息插入接口先插入人员信息后再插入处方信息！");
                                }
                                else
                                {
                                    certno = dt.Rows[0]["certno"].ToString();
                                }
                            }

                            cmd.CommandText = "select * from fsi_prescription where auth_rxno=@auth_rxno";
                            cmd.Parameters.AddWithValue("@auth_rxno", auth_rxno);
                            using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                            {
                                dtrxinfo.Load(reader);
                                cmd.Parameters.Clear();
                                if (dtrxinfo.Rows.Count != 0)
                                {
                                    throw new Exception($"插入处方记录表失败！处方信息校验失败！已存在auth_rxno为 {auth_rxno} 的处方信息，不允许再次插入！");
                                }
                            }
                            /*插入处方汇总信息*/
                            cmd.Transaction = transaction;
                            try
                            {
                                cmd.CommandText = "INSERT INTO `data`.`fsi_prescription` (`certno`, `psn_no`, `auth_rxno`, `epc_token`, `expires_in`, `fixmedins_code`, " +
                                    "`fixmedins_name`, `prsc_time`, `dise_codg`, `dise_name`, `valid_end_time`, `hi_rxno`, `rx_trace_code`, `prsc_dept_name`, `rx_type_code`, " +
                                    "`rx_type_name`, `long_rx_flag`, `file_suffix`, `rx_file`, `med_type`, `otp_ipt_flag`, `patn_name`, `patn_age`, `patn_hgt`, `patn_wt`," +
                                    " `gend`, `geso_val`, `nwb_flag`, `nwb_age`, `suck_prd_flag`, `algs_his`, `main_diag_code`, `main_diag_name`, `dise_cond_dscr`, `ID`) " +
                                    "VALUES (@certno, @psn_no, @auth_rxno, @epc_token," +
                                    " @expires_in, @fixmedins_code, @fixmedins_name, @prsc_time, @dise_codg, @dise_name, @valid_end_time, " +
                                    "@hi_rxno, @rx_trace_code, @prsc_dept_name, @rx_type_code, @rx_type_name, @long_rx_flag, @file_suffix, @rx_file, @med_type, @otp_ipt_flag, " +
                                    "@patn_name, @patn_age, @patn_hgt, @patn_wt, @gend,@geso_val, @nwb_flag, @nwb_age, @suck_prd_flag, @algs_his, @main_diag_code, " +
                                    " @main_diag_name, @dise_cond_dscr, @ID)";
                                cmd.Parameters.AddWithValue("@certno", certno);
                                cmd.Parameters.AddWithValue("@psn_no", psn_no);
                                cmd.Parameters.AddWithValue("@auth_rxno", auth_rxno);
                                cmd.Parameters.AddWithValue("@epc_token", epc_token);
                                cmd.Parameters.AddWithValue("@expires_in", epcInfoInput.outputJson.output.data.prsc_time);
                                cmd.Parameters.AddWithValue("@fixmedins_code", epcInfoInput.outputJson.output.data.fixmedins_code);
                                cmd.Parameters.AddWithValue("@fixmedins_name", epcInfoInput.outputJson.output.data.fixmedins_name);
                                cmd.Parameters.AddWithValue("@prsc_time", epcInfoInput.outputJson.output.data.prsc_time);
                                cmd.Parameters.AddWithValue("@dise_codg", epcInfoInput.outputJson.output.rxOtpinfo.dise_codg);
                                cmd.Parameters.AddWithValue("@dise_name", epcInfoInput.outputJson.output.rxOtpinfo.dise_name);
                                cmd.Parameters.AddWithValue("@valid_end_time", epcInfoInput.outputJson.output.data.valid_end_time);
                                cmd.Parameters.AddWithValue("@hi_rxno", epcInfoInput.outputJson.output.data.hi_rxno);
                                cmd.Parameters.AddWithValue("@rx_trace_code", epcInfoInput.outputJson.output.data.rx_trace_code);
                                cmd.Parameters.AddWithValue("@prsc_dept_name", epcInfoInput.outputJson.output.data.prsc_dept_name);
                                cmd.Parameters.AddWithValue("@rx_type_code", epcInfoInput.outputJson.output.data.rx_type_code);
                                cmd.Parameters.AddWithValue("@rx_type_name", epcInfoInput.outputJson.output.data.rx_type_name);
                                cmd.Parameters.AddWithValue("@long_rx_flag", epcInfoInput.outputJson.output.data.long_rx_flag);
                                cmd.Parameters.AddWithValue("@file_suffix", epcInfoInput.outputJson.output.data.file_suffix);
                                cmd.Parameters.AddWithValue("@rx_file", epcInfoInput.outputJson.output.data.rx_file);
                                cmd.Parameters.AddWithValue("@med_type", epcInfoInput.outputJson.output.rxOtpinfo.med_type);
                                cmd.Parameters.AddWithValue("@otp_ipt_flag", epcInfoInput.outputJson.output.rxOtpinfo.otp_ipt_flag);
                                cmd.Parameters.AddWithValue("@patn_name", epcInfoInput.outputJson.output.rxOtpinfo.patn_name);
                                cmd.Parameters.AddWithValue("@patn_age", epcInfoInput.outputJson.output.rxOtpinfo.patn_age);
                                cmd.Parameters.AddWithValue("@patn_hgt", epcInfoInput.outputJson.output.rxOtpinfo.patn_hgt);
                                cmd.Parameters.AddWithValue("@patn_wt", epcInfoInput.outputJson.output.rxOtpinfo.patn_wt);
                                cmd.Parameters.AddWithValue("@geso_val", epcInfoInput.outputJson.output.rxOtpinfo.geso_val);
                                cmd.Parameters.AddWithValue("@nwb_flag", epcInfoInput.outputJson.output.rxOtpinfo.nwb_flag);
                                cmd.Parameters.AddWithValue("@nwb_age", epcInfoInput.outputJson.output.rxOtpinfo.nwb_age);
                                cmd.Parameters.AddWithValue("@suck_prd_flag", epcInfoInput.outputJson.output.rxOtpinfo.suck_prd_flag);
                                cmd.Parameters.AddWithValue("@algs_his", epcInfoInput.outputJson.output.rxOtpinfo.algs_his);
                                cmd.Parameters.AddWithValue("@main_diag_code", epcInfoInput.outputJson.output.rxOtpinfo.main_diag_code);
                                cmd.Parameters.AddWithValue("@main_diag_name", epcInfoInput.outputJson.output.rxOtpinfo.main_diag_name);
                                cmd.Parameters.AddWithValue("@dise_cond_dscr", epcInfoInput.outputJson.output.rxOtpinfo.dise_cond_dscr);
                                await cmd.ExecuteNonQueryAsync();
                                cmd.Parameters.Clear();
                            }
                            catch (Exception ex)
                            {
                                transaction.Rollback();
                                throw new Exception($"插入处方记录表失败！处方汇总信息插入失败！错误内容：{ex.Message}");
                            }
                            string error="";
                            foreach (var item in dataList)
                            {
                                try
                                {
                                    cmd.CommandText = "INSERT INTO `data`.`fsi_prescription_detail` (`psn_no`, `auth_rxno`, `med_list_codg`, `fixmedins_hilist_id`, " +
                                        "`hosp_prep_flag`, `rx_item_type_code`, `rx_item_type_name`, `tcmdrug_type_name`, `tcmdrug_type_code`, `tcmherb_foote`, `medn_type_code`, " +
                                        "`medn_type_name`, `main_medc_flag`, `urgt_flag`, `bas_medn_flag`, `imp_drug_flag`, `drug_prodname`, `drug_genname`, `drug_dosform`, `drug_spec`," +
                                        " `prdr_name`, `drug_cnt`, `medc_way_codg`, `medc_way_dscr`, `medc_endtime`, `medc_days`, `medc_begntime`, `drug_dosunt`, `sin_doscnt`, `sin_dosunt`," +
                                        " `used_frqu_codg`, `used_frqu_name`, `drug_totlcnt`, `drug_totlnt_emp`, `own_expense_flag`, `hi_nego_drug_flag`, `refer_d_channel_flag`, " +
                                        "`bidding_drug_flag`, `hosp_appr_flag`) VALUES (@psn_no, @auth_rxno,@med_list_codg,@fixmedins_hilist_id, @hosp_prep_flag, @rx_item_type_code,@rx_item_type_name, " +
                                        "@tcmdrug_type_name, @tcmdrug_type_code,@tcmherb_foote, @medn_type_code, @medn_type_name, @main_medc_flag, @urgt_flag, @bas_medn_flag, @imp_drug_flag," +
                                        " @drug_prodname, @drug_genname, @drug_dosform, @drug_spec, @prdr_name , @drug_cnt, @medc_way_codg, @medc_way_dscr, @medc_endtime, @medc_days, @medc_begntime, " +
                                        "@drug_dosunt, @sin_doscnt,@sin_dosunt, @used_frqu_codg, @used_frqu_name, @drug_totlcnt, @drug_totlnt_emp, @own_expense_flag,@hi_nego_drug_flag, @refer_d_channel_flag, " +
                                        "@bidding_drug_flag, @hosp_appr_flag)";

                                    cmd.Parameters.AddWithValue("@psn_no", psn_no);
                                    cmd.Parameters.AddWithValue("@auth_rxno", auth_rxno);
                                    cmd.Parameters.AddWithValue("@med_list_codg", item.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", item.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@hosp_prep_flag", item.hosp_prep_flag);
                                    cmd.Parameters.AddWithValue("@rx_item_type_code", item.rx_item_type_code);
                                    cmd.Parameters.AddWithValue("@rx_item_type_name", item.rx_item_type_name);
                                    cmd.Parameters.AddWithValue("@tcmdrug_type_name", item.tcmdrug_type_name);
                                    cmd.Parameters.AddWithValue("@tcmdrug_type_code", item.tcmdrug_type_code);
                                    cmd.Parameters.AddWithValue("@tcmherb_foote", item.tcmherb_foote);
                                    cmd.Parameters.AddWithValue("@medn_type_code", item.medn_type_code);
                                    cmd.Parameters.AddWithValue("@medn_type_name", item.medn_type_name);
                                    cmd.Parameters.AddWithValue("@main_medc_flag", item.main_medc_flag);
                                    cmd.Parameters.AddWithValue("@urgt_flag", item.urgt_flag);
                                    cmd.Parameters.AddWithValue("@bas_medn_flag", item.bas_medn_flag);
                                    cmd.Parameters.AddWithValue("@imp_drug_flag", item.imp_drug_flag);
                                    cmd.Parameters.AddWithValue("@drug_prodname", item.drug_prodname);
                                    cmd.Parameters.AddWithValue("@drug_genname", item.drug_genname);
                                    cmd.Parameters.AddWithValue("@drug_dosform", item.drug_dosform);
                                    cmd.Parameters.AddWithValue("@drug_spec", item.drug_spec);
                                    cmd.Parameters.AddWithValue("@prdr_name", item.prdr_name);
                                    cmd.Parameters.AddWithValue("@drug_cnt", item.drug_cnt);
                                    cmd.Parameters.AddWithValue("@medc_way_codg", item.medc_way_codg);
                                    cmd.Parameters.AddWithValue("@medc_way_dscr", item.medc_way_dscr);
                                    cmd.Parameters.AddWithValue("@medc_endtime", item.medc_endtime);
                                    cmd.Parameters.AddWithValue("@medc_days", item.medc_days);
                                    cmd.Parameters.AddWithValue("@medc_begntime", item.medc_begntime);
                                    cmd.Parameters.AddWithValue("@drug_dosunt", item.drug_dosunt);
                                    cmd.Parameters.AddWithValue("@sin_doscnt", item.sin_doscnt);
                                    cmd.Parameters.AddWithValue("@sin_dosunt", item.sin_dosunt);
                                    cmd.Parameters.AddWithValue("@used_frqu_codg", item.used_frqu_codg);
                                    cmd.Parameters.AddWithValue("@used_frqu_name", item.used_frqu_name);
                                    cmd.Parameters.AddWithValue("@drug_totlcnt", item.drug_totlcnt);
                                    cmd.Parameters.AddWithValue("@drug_totlnt_emp", item.drug_totlnt_emp);
                                    cmd.Parameters.AddWithValue("@own_expense_flag", item.own_expense_flag);
                                    cmd.Parameters.AddWithValue("@hi_nego_drug_flag", item.hi_nego_drug_flag);
                                    cmd.Parameters.AddWithValue("@refer_d_channel_flag", item.refer_d_channel_flag);
                                    cmd.Parameters.AddWithValue("@bidding_drug_flag", item.bidding_drug_flag);
                                    cmd.Parameters.AddWithValue("@hosp_appr_flag", item.hosp_appr_flag);
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                catch (Exception ex)
                                {
                                    error = error + $" 【{item.drug_genname}({item.drug_prodname})/{item.drug_spec}】插入处方记录表失败！处方明细信息插入失败！：" + ex.Message + "|";
                                    cmd.Parameters.Clear();
                                }
                            }
                            if (error != "")
                            {
                                transaction.Rollback();
                                throw new Exception(error);

                            }
                            else
                            {
                                transaction.Commit();
                                //transaction.Rollback();
                                return Json(new { code = 0, msg = "", data = "插入成功!" });
                            }
                        }
                    }
                        
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync();
                    }
                }
            }
        }
        /// <summary>
        /// 删除医保人员信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeleteEpcInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> DeleteEpcInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeleteEpcInfo";

            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：入参为空!请检查!", data = "" };
                        return Json(response);
                    }
                    var fsiRequest = JsonConvert.DeserializeObject<DeleteEpcInfoInput>(request.Content.ReadAsStringAsync().Result);
                    if (string.IsNullOrEmpty(fsiRequest.auth_rxno))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的处方授权编号auth_rxno为空!", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    DataTable dt = new DataTable();
                    using (MySqlTransaction transaction = conn.BeginTransaction())
                    {
                        using (MySqlCommand cmd = conn.CreateCommand())
                        {
                            cmd.CommandText = "select * from fsi_prescription where auth_rxno=@auth_rxno";
                            cmd.Parameters.AddWithValue("@auth_rxno", fsiRequest.auth_rxno);
                            using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                            {
                                dt.Load(reader);
                                cmd.Parameters.Clear();
                                if (dt.Rows.Count > 0)
                                {
                                    cmd.Transaction = transaction;
                                    try
                                    {
                                        cmd.CommandText = "delete from fsi_prescription where auth_rxno=@auth_rxno";
                                        cmd.Parameters.AddWithValue("@auth_rxno", fsiRequest.auth_rxno);
                                        await cmd.ExecuteNonQueryAsync();
                                        cmd.Parameters.Clear();
                                        cmd.CommandText = "delete from fsi_prescription_detail where auth_rxno=@auth_rxno";
                                        cmd.Parameters.AddWithValue("@auth_rxno", fsiRequest.auth_rxno);
                                        await cmd.ExecuteNonQueryAsync();
                                        cmd.Parameters.Clear();
                                        transaction.Commit();
                                        var response = new { code = 0, msg = "", data = "删除医保处方信息记录成功!" };
                                        return Json(response);
                                    }
                                    catch (Exception ex)
                                    {
                                        transaction.Rollback();
                                        throw ex;
                                    }
                                }
                                else
                                {
                                    var response = new { code = 100, msg = $"业务参数校验失败：删除医保处方信息记录失败！传入的处方授权编号auth_rxno:{fsiRequest.auth_rxno}查询到{dt.Rows.Count}条相关数据！无需删除！", data = "" };
                                    return Json(response);
                                }
                            }

                        }
                    }                     
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync();
                    }
                }
            }
        }

        /// <summary>
        /// 新增事前事中违规商品控制
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("InsertRiskconserviceProductInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> InsertRiskconserviceProductInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/InsertRiskconserviceProductInfo";
            
            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：入参为空!请检查!", data = "" };
                        return Json(response);
                    }
                    InsertRiskconserviceProductInfoInput fsiRequest = JsonConvert.DeserializeObject<InsertRiskconserviceProductInfoInput>(request.Content.ReadAsStringAsync().Result);
                    if (string.IsNullOrEmpty(fsiRequest.med_list_codg)||string.IsNullOrEmpty(fsiRequest.rule_name)|| string.IsNullOrEmpty(fsiRequest.vola_cont) || string.IsNullOrEmpty(fsiRequest.vola_evid))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：有必传参数为空!当前入参：{request.Content.ReadAsStringAsync().Result}", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    using (MySqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "INSERT INTO `data`.`fsi_riskconserviceproduct` (`ID`, `med_list_codg`, `rule_id`, " +
                            "`rule_name`, `vola_cont`, `sev_deg`, `vola_evid`, `vola_bhvr_type`) VALUES (null, @med_list_codg, " +
                            "@rule_id, @rule_name, @vola_cont, @sev_deg,@vola_evid, @vola_bhvr_type)";
                        cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.med_list_codg);
                        cmd.Parameters.AddWithValue("@rule_id", fsiRequest.rule_id ?? DateTime.Now.ToString("yyyyMMddHHmmssfff"));
                        cmd.Parameters.AddWithValue("@rule_name", fsiRequest.rule_name);
                        cmd.Parameters.AddWithValue("@vola_cont", fsiRequest.vola_cont);
                        cmd.Parameters.AddWithValue("@sev_deg", fsiRequest.sev_deg ?? "1");
                        cmd.Parameters.AddWithValue("@vola_evid", fsiRequest.vola_evid);
                        cmd.Parameters.AddWithValue("@vola_bhvr_type", fsiRequest.vola_bhvr_type ?? "2");
                        await cmd.ExecuteNonQueryAsync();
                        cmd.Parameters.Clear();
                        var response = new { code = 0, msg = "", data = "插入成功!" };
                        return Json(response);
                    }
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync();
                    }
                }
            }
        }


        /// <summary>
        /// 删除事前事中违规商品控制
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        [Route("DeleteRiskconserviceProductInfo")]
        [HttpPost]
        public async Task<IHttpActionResult> DeleteRiskconserviceProductInfo(HttpRequestMessage request)
        {
            string UrlName = "/FsiAdminApi/DeleteRiskconserviceProductInfo";

            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                    {
                        var response = new { code = 100, msg = $"参数校验失败：入参为空!请检查!", data = "" };
                        return Json(response);
                    }
                    InsertRiskconserviceProductInfoInput fsiRequest = JsonConvert.DeserializeObject<InsertRiskconserviceProductInfoInput>(request.Content.ReadAsStringAsync().Result);
                    if (string.IsNullOrEmpty(fsiRequest.med_list_codg) )
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的国家编码为空!", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    DataTable dt = new DataTable();
                    using (MySqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "select * from fsi_riskconserviceproduct where med_list_codg=@med_list_codg";
                        cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.med_list_codg);
                        using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                        {
                            dt.Load(reader);
                            cmd.Parameters.Clear();
                            if (dt.Rows.Count > 0)
                            {
                                cmd.CommandText = "delete from fsi_riskconserviceproduct where med_list_codg=@med_list_codg";
                                cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.med_list_codg);
                                await cmd.ExecuteNonQueryAsync();
                                cmd.Parameters.Clear();
                                var response = new { code = 0, msg = "", data = "删除事前事中违规商品控制记录成功!" };
                                return Json(response);
                            }
                            else
                            {
                                var response = new { code = 100, msg = $"业务参数校验失败：删除事前事中违规商品控制记录失败！传入的国家编码{fsiRequest.med_list_codg}查询到{dt.Rows.Count}条相关数据！无需删除！", data = "" };
                                return Json(response);
                               
                            }
                        }

                    }
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync();
                    }
                }
            }
        }

        /// <summary>
        /// 查询医保表相关的数据
        /// </summary>
        /// <param name="pwd"></param>
        /// <param name="tablename"></param>
        /// <param name="pagesize"></param>
        /// <param name="nowpage"></param>
        /// <returns></returns>
        [Route("SelectFsiTableData")]
        [HttpGet]
        public async Task<IHttpActionResult> SelectFsiTableData(string pwd,string tablename, int? pagesize = 10, int? nowpage = 1)
        {

            string UrlName = "/FsiAdminApi/SelectFsiTableData";
            if (nowpage <= 0 || pagesize <= 0)
            {

                var response = new { code = 100, msg = $"服务端数据校验不通过：分页参数异常！不允许小于等于0的值传入！当前页传入:{nowpage} 每页大小传入：{pagesize}", data = "" };
                LogHelper.Info($"[{UrlName}]参数异常！分页参数异常！当前页传入:{nowpage} 每页大小传入：{pagesize}！");
                return Json(response);
            }
            //当前分页的最大页数
            int maxpage = (int)((nowpage - 1) * pagesize);

            string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                try
                {
                    bool isAuth = await PublicMethod.ApiPasswordAuth("SelectFsiTableData", pwd);
                    if (isAuth != true)
                    {
                        var response = new { code = 100, msg = $"该接口需要管理员鉴权，鉴权密钥错误！", data = "" };
                        return Json(response);
                    }
                    await conn.OpenAsync();
                    using (MySqlCommand cmd = conn.CreateCommand())
                    {

                        cmd.CommandText = $"select * from {tablename} limit @maxpage,@pagesize";
                        cmd.Parameters.AddWithValue("@maxpage", maxpage);
                        cmd.Parameters.AddWithValue("@pagesize", pagesize);
                        using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                        {
                            DataTable dt = new DataTable();
                            dt.Load(reader);
                            var response = new { code = 0, msg = "", data = dt };
                            LogHelper.Info($"[{UrlName}]请求成功！");
                            return Json(response);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string Errnum = LogHelper.GetErrornumber();
                    var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace}", data = "" };
                    LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                    return Json(response);
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        await conn.CloseAsync(); 
                    }
                }
            }
        }
        
        /// <summary>
        /// 生成处方PDF文件（7203 7204转换）
        /// </summary>
        /// <param name="request">处方中心入参</param>
        /// <param name="infno">接口转换类型 7203Output 7204Input</param>
        /// <returns></returns>
        [Route("GeneratePrescriptionFile")]
        [HttpPost]
        public  IHttpActionResult GeneratePrescriptionFile(HttpRequestMessage request,string infno)
        {
            string UrlName = "/FsiAdminApi/GeneratePrescriptionFile";
            try
            {
                string filePath = AppDomain.CurrentDomain.BaseDirectory+"\\file\\PDF";
                string filename = "YBPDF" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".pdf";
                if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                {
                    var response = new { code = 100, msg = $"参数校验失败：入参为空!请检查!", data = "" };
                    return Json(response);
                }

                if (infno=="7203Output")
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiHeader<outputDataOpsp7203>>(request.Content.ReadAsStringAsync().Result);
                    string rxFile = fsiRequest.output.data.rx_file;
                    if (!string.IsNullOrEmpty(rxFile))
                    {
                        bool state;
                        string path = PublicMethod.Base64StringToFile(out state,rxFile, filePath,filename);
                        if (state==true)
                        {
                            var output = new
                            {
                                code = 0,
                                msg = "",
                                data = new OutputGeneratePrescriptionFile
                                {
                                    prescription_file_Datetime=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                    prescription_file_name=filename,
                                    prescription_file_path=path
                                }
                            };
                            return Json(output);
                        }
                        else
                        {
                            throw new Exception(path);
                        }
                    }
                    else
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的转换类型{infno}入参的rx_file参数为空!请检查入参是否为浙江省医保7203出参报文!", data = "" };
                        return Json(response);
                    }

                }
                else if (infno == "7204Input")
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputOpsp7204Request>>(request.Content.ReadAsStringAsync().Result);
                    string rxFile = fsiRequest.Input.data.rx_file;
                    if (!string.IsNullOrEmpty(rxFile))
                    {
                        bool state;
                        string path = PublicMethod.Base64StringToFile(out state, rxFile, filePath, filename);
                        if (state == true)
                        {
                            var output = new
                            {
                                code = 0,
                                msg = "",
                                data = new OutputGeneratePrescriptionFile
                                {
                                    prescription_file_Datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                    prescription_file_name = filename,
                                    prescription_file_path = path
                                }
                            };
                            return Json(output);
                        }
                        else
                        {
                            throw new Exception(path);
                        }
                    }
                    else
                    {
                        var response = new { code = 100, msg = $"参数校验失败：传入的转换类型{infno}入参的rx_file参数为空!请检查入参是否为浙江省医保7203出参报文!", data = "" };
                        return Json(response);
                    }
                }
                else
                {
                    var response = new { code = 100, msg = $"参数校验失败：传入的{infno}转换类型未被定义！请检查!", data = "" };
                    return Json(response);
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }

        /// <summary>
        /// 获取设置配置
        /// </summary>
        /// <returns></returns>
        [Route("GetSettingConfig")]
        [HttpGet]
        public IHttpActionResult GetSettingConfig()
        {
            string UrlName = "/FsiAdminApi/GetSettingConfig";
            try
            {
                var response = new
                {
                    code = 0,
                    msg = "",
                    data = new
                    {
                        epcTokenInfo= new
                        {
                            appId=FsiEpcTokeninfo.appId,
                            appSecret=FsiEpcTokeninfo.appSecret,
                            privateKey = FsiEpcTokeninfo.privateKey,
                            publicKey = FsiEpcTokeninfo.publicKey
                        },
                        cardnoInfo = new
                        {
                            defautCardNo = FsiDatainfo.Defautlcardno,
                            eccCodeCardNo = FsiDatainfo.Ecccodecardno,
                            jiangsuDefautlcardno = FsiDatainfo.JiangsuDefautlcardno,
                        },
                        apiStateInfo = new
                        {
                            stateNeusJiangsuApi = FsiDatainfo.stateNeusJiangsuApi,
                            stateFsiApi = FsiDatainfo.stateFsiApi,
                            stateFsiEpcApi = FsiDatainfo.stateFsiEpcApi,
                            statesSignon = FsiDatainfo.statesignon,
                            stateShandongBinzhouApi = FsiDatainfo.stateShandongBinzhouApi,
                            stateShandongDarewayApi = FsiDatainfo.stateShandongDarewayApi,
                            stateShandongJxcApi = FsiDatainfo.stateShandongJxcApi,
                            stateLocalApiInInternal = FsiDatainfo.stateLocalApiInInternal
                        },
                        acctPayInfo = new
                        {
                            fundPaySumamt = FsiDatainfo.fund_pay_sumamt,
                            psnCashPay = FsiDatainfo.psn_cash_pay,
                            acctPay = FsiDatainfo.acct_pay,
                            clcYearAcctPay = FsiDatainfo.clcYearAcctPay,
                            crtYearAcctPay =FsiDatainfo.crtYearAcctPay,
                            acctMulaidPay = FsiDatainfo.acct_mulaid_pay
                        },
                        otherPayInfo = new
                        {
                            cvlservPay = FsiDatainfo.cvlserv_pay,
                            hifdmPay = FsiDatainfo.hifdm_pay,
                            hifmiPay = FsiDatainfo.hifmi_pay,
                            actPayDedc = FsiDatainfo.act_pay_dedc,
                            hifobPay = FsiDatainfo.hifob_pay,
                            othPay = FsiDatainfo.oth_pay,
                            hifesPay =FsiDatainfo.hifes_pay,
                            fulamtOwnpayAmt = FsiDatainfo.fulamt_ownpay_amt,
                            hospPartAmt = FsiDatainfo.hosp_part_amt,
                            inscpScpAmt = FsiDatainfo.inscp_scp_amt,
                            mafPay = FsiDatainfo.maf_pay,
                            overlmtSelfpay = FsiDatainfo.overlmt_selfpay,
                            preselfpayAmt = FsiDatainfo.preselfpay_amt
                        }
                    }
                };
                return Json(response);    
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var response = new { code = -1, msg = $"[{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ", data = "" };
                LogHelper.Error($"[{UrlName}][{Errnum}]服务端系统异常：服务端系统处理异常!请联系管理员！错误内容：{ex.Message} 异常来源：{ex.StackTrace} ");
                return Json(response);
            }
        }
    }
}
